<template>
	<view class="content">
	<!-- <view class="content" v-if="goodsInfo!=''"> -->
		<view class="top-edit">
			<image src="../../../static/common/goos-back.png" class="goos-back" @tap="goBack"></image>
			<!-- <image src="../../../static/common/goos-edit.png" class="goos-edit"></image> -->
		</view>
		<swiper class="good-imgs" indicator-dots="true" autoplay="true" circular="true">
			<!-- <swiper-item v-for="(img,index) in goodsInfo.small_images.string" :key="index">
				<image :src="img" class="goos-img"></image>
			</swiper-item> -->
			<swiper-item>
				<image  :src="getImg(goods.giftImg)" class="goos-img"></image>
			</swiper-item>
		</swiper>
		<!-- 抢购信息 -->
		<view class="buy-info">
			<view class="good-priceaa">
				￥{{goods.price?goods.price:'-'}}
			</view>
			<view class="good-discount11">
				<view class="xiadan-price">下单价  ¥ {{goods.productActualPrice}}</view>
				<view class="fanxian-price">返现 ¥{{goods.productActualPrice&&goods.price?calculate(goods.productActualPrice,goods.price):'-'}}</view>
			</view>
			<!-- <view class="limit-time">
				<view class="limit-time-text">
					{{task_status?"活动已结束":"距结束仅剩"}}
					
				</view>
				<view class="time-num">
					<view class="number">{{day}}</view><view class="text-world">天</view>
					<view class="number">{{hours}}</view><view class="text-world">时</view>
					<view class="number">{{minute}}</view><view class="text-world">分</view>
					<view class="number">{{secound}}</view><view class="text-world">秒</view>
				</view>
			</view> -->
		</view>
		<!-- 商品标题 -->
		<view class="goos-title-block">
			<view class="good-title">
				<image src="../../../static/common/taobao.png" class="name-icon"></image>
				<text class="good-name2">{{goods.giftName?goods.giftName:'-'}}</text>
			</view>
		</view>
		<!-- 推荐词 -->
		<view class="recommend">
			<image src="../../../static/common/icon-sub-good-detail.png" class="recommend-img"></image>
			<view class="recommend-text">
				商家已缴纳¥{{goods.productActualPrice}}元保证金，请放心购买！
			</view>
		</view>
		<!-- 商品详情 -->
		<view class="goods-info">
			<image src="../../../static/common/goos-remark.png" class="goos-info"></image>
			<view class="goods-desc-list">
				<view class="task-remark">{{goods.remark?goods.remark:"暂无商品说明"}}</view>
			</view>
			
		</view>
		<!-- 拍前必看 -->
		<view class="read">
			<!-- <image src="../../../static/common/goos-info.png" class="goos-info positionimg"></image> -->
			<view class="read-title">拍前必看</view>
			<view class="read-me">
				<view class="text-one">
					<view class="line-one">遇到问题可联系平台客服</view>
					<view class="line-one">切勿在手机淘宝上咨询商家相关问题</view>
				</view>
			</view>
			<view class="read-rule-one one">
				<text>1. 快递说明: </text>
				默认发申通、圆通、天天。新疆、西藏等偏远地区暂不支持发货，请买家勿拍            
			</view>
			<view class="read-rule-one one">
				<text>2. 购买说明: </text>
				请务必按照下单流程拍指定店铺、指定价格的商品， 在45分钟内完成购买返回本页面回填订单号，未及时回填单号不 享受活动返还，需按照实拍价购买所拍商品            
			</view>
			<view class="read-rule-one two">
				<text>3. 温馨提示: </text>
				严禁使用任何返利软件下单购买，违反者从返款中 扣除返利所得，严重者封号处理。请不要使用淘金币，店铺优惠 券，分期付款下单！
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="bottom-btn">
			<navigator url="../sub-kefu/sub-kefu" hover-class="none">
				<view class="kefu">
					<image src="../../../static/common/sbu-home-top-icon.png" class="collection"></image>
					<view class="kefu-text">联系客服</view>
				</view>
			</navigator>
			
			<view class="surplus">剩余{{goods.unfinishCount}}/{{goods.orderCount}}</view>
			<view class="qianggou" 
			:class="{'isendcolor':task_status}" 
			@tap="makeOrder">
				{{task_status?"还有机会":"立即抢购"}}
			</view>
		</view>
		
		<!-- 分享商品 -->
		
	</view>
</template>

<script>
	export default{
		name:"goodDetail",
		data(){
			return{
				apptoken:"",
				goods:"",
				day:"",
				hours:"",
				minute:"",
				secound:"",
				task_status:false,
				taobaoID:"",
				CJFAddress:""
			}
		},
		onLoad(options) {
			this.apptoken = uni.getStorageSync("apptoken");
			this.taobaoID = uni.getStorageSync("taobaoID");
			this.CJFAddress = uni.getStorageSync("CJFAddress");
			//console.log("taobaoID=" +this.taobaoID)
			//console.log("CJFAddress=" + JSON.stringify(this.CJFAddress))
			const _this = this;
			uni.getStorage({
				key:"task_detail",
				success(res) {
					_this.goods = res.data;
					console.log(_this.goods);
					if(res.data.unfinishCount == 0){
						_this.task_status = !_this.task_status;
					}
					_this.handleTime(res.data.releaseTime);//处理时间戳，倒计时
				}
			})
			
		},
		methods:{
			calculate(v1,v2){
				//return Number(v1) - Number(v2);
				return (Number(v1)*1000 - Number(v2)*1000)/1000;
			},
			handleTime(time){
				const _this = this;
				//处理时间戳，倒计时
				let a = Date.now();
				//const  resultTime  = 1589091661000;
				//const endTimer = resultTime - a;
				
				const endTimer = time - a;
				if(endTimer < 0){
					//任务已结束
					
					_this.day = "00";
					_this.hours = "00";
					_this.minute = "00";
					_this.secound = "00";
					//console.log("任务已结束")
				}else{
					 setInterval(function(){
						let nowTime = new Date();
						//let endTime = 1589091661000;
						let endTime = time;
						let t = endTime - nowTime.getTime();
						let d=Math.floor(t/1000/60/60/24);
						let hour=Math.floor(t/1000/60/60%24);
						let min=Math.floor(t/1000/60%60);
						let sec=Math.floor(t/1000%60);
							if (d < 10) {
									 d = "0" + d;
							}
							if (hour < 10) {
									 hour = "0" + hour;
							}
							if (min < 10) {
									 min = "0" + min;
							}
							if (sec < 10) {
									 sec = "0" + sec;
							}
							_this.day = d;
							_this.hours = hour;
							_this.minute = min;
							_this.secound = sec;
					},1000);
				}
			},
			getImg(url){
				//处理图片路劲
				if(url && url.indexOf('http')==-1){
					return	this.$CommonJS.getBaseImgUrl(url);
				}else{
					return url
				}
			},
			makeOrder(){
				//下单
				const _this = this;
				//验证用户是否绑定了淘宝和收货地址，如果未绑定则跳转到相应页面
				// if(!this.taobaoID){
				// 	this.showTostModel("淘宝账号");
				// }else if(!this.CJFAddress.address){
				// 	this.showTostModel("收货地址");
				// }else{
				// 	uni.request({
				// 		url:this.$API.URL + this.$API.task_get,
				// 		data:{apptoken:this.apptoken,sortOrder:this.goods.sortOrder},
				// 		success(res) {
				// 			console.log(res)
				// 			if(res.data.success){
				// 				_this.$CommonJS.navigateTo('../../subBack/sub-makeorder/sub-makeorder?taskId='+res.data.data.id);
				// 			}else{
				// 				_this.goods.unfinishCount = 0;
				// 				_this.task_status = !_this.task_status;
				// 				_this.$CommonJS.showToast(res.data.msg);
				// 			}
				// 		}
				// 	})
				// }
				uni.request({
					url:this.$API.URL + this.$API.task_get,
					data:{apptoken:this.apptoken,sortOrder:this.goods.sortOrder,giftLevel:this.goods.giftLevel,giftId:this.goods.giftId},
					success(res) {
						console.log(res)
						if(res.data.success){
							_this.$CommonJS.navigateTo('../../subBack/sub-makeorder/sub-makeorder?taskId='+res.data.data.id);
						}else{
							//_this.goods.unfinishCount = 0;
							//_this.task_status = !_this.task_status;
							_this.$CommonJS.showToast(res.data.msg);
						}
					}
				})
				//_this.$CommonJS.navigateTo('../../subBack/sub-makeorder/sub-makeorder?taskId='+_this.goods.taskId);
			},
			showTostModel(str){
				const _this = this;
				uni.showModal({
					title:"温馨提示",
					content:"您还没有绑"+ str +",不能接单!!!,请前往个人中心绑定,再来接单吧",
					showCancel:false,
					success(res) {
						if(res.confirm){
							_this.$CommonJS.navigateTo('../sub-userInfo/sub-userInfo');
						}
					}
				})
			},
			goBack(){
				uni.navigateBack()
			},
		}
	}
</script>

<style scoped>
	@import url("sub-gooddetail.css");
</style>
